package com.abluedog.c1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class FileChannelTransferToTest {

    public static void main(String[] args) {
        try (FileChannel from = new FileInputStream("data.txt").getChannel();
             FileChannel to = new FileOutputStream("data2.txt").getChannel()) {
            //大于2g的文件需要分开读取
            long size = from.size();
            for (long l = size; l > 0; ) {
                 l -= from.transferTo(size - l, size, to);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
